package com.miracle.film.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.miracle.film.domain.FlmActor;
import com.miracle.film.service.IFlmActorService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 演员导演Controller
 * 
 * @author miracle
 * @date 2022-12-30
 */
@RestController
@RequestMapping("/film/actor")
public class FlmActorController extends BaseController
{
    @Autowired
    private IFlmActorService flmActorService;

    /**
     * 查询演员导演列表
     */
    @PreAuthorize("@ss.hasPermi('film:actor:list')")
    @GetMapping("/list")
    public TableDataInfo list(FlmActor flmActor)
    {
        startPage();
        List<FlmActor> list = flmActorService.selectFlmActorList(flmActor);
        return getDataTable(list);
    }

    /**
     * 导出演员导演列表
     */
    @PreAuthorize("@ss.hasPermi('film:actor:export')")
    @Log(title = "演员导演", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, FlmActor flmActor)
    {
        List<FlmActor> list = flmActorService.selectFlmActorList(flmActor);
        ExcelUtil<FlmActor> util = new ExcelUtil<FlmActor>(FlmActor.class);
        util.exportExcel(response, list, "演员导演数据");
    }

    /**
     * 获取演员导演详细信息
     */
    @PreAuthorize("@ss.hasPermi('film:actor:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Integer id)
    {
        return AjaxResult.success(flmActorService.selectFlmActorById(id));
    }

    /**
     * 新增演员导演
     */
    @PreAuthorize("@ss.hasPermi('film:actor:add')")
    @Log(title = "演员导演", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody FlmActor flmActor)
    {
        return toAjax(flmActorService.insertFlmActor(flmActor));
    }

    /**
     * 修改演员导演
     */
    @PreAuthorize("@ss.hasPermi('film:actor:edit')")
    @Log(title = "演员导演", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody FlmActor flmActor)
    {
        return toAjax(flmActorService.updateFlmActor(flmActor));
    }

    /**
     * 删除演员导演
     */
    @PreAuthorize("@ss.hasPermi('film:actor:remove')")
    @Log(title = "演员导演", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Integer[] ids)
    {
        return toAjax(flmActorService.deleteFlmActorByIds(ids));
    }
}
